package com.dsh.storeManagement.service.Impl;

import com.dsh.storeManagement.dao.AreaDao;
import com.dsh.storeManagement.dao.StoreDao;
import com.dsh.storeManagement.entity.dto.AreaDto;
import com.dsh.storeManagement.entity.vo.AdminAreaVo;
import com.dsh.storeManagement.entity.vo.AreaNameVo;
import com.dsh.storeManagement.entity.dto.GradeDto;
import com.dsh.storeManagement.entity.dto.UpdateAreaDto;
import com.dsh.storeManagement.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AreaServiceImpl implements AreaService {
    @Autowired
    AreaDao areaDao;
    @Autowired
    StoreDao storeDao;
    @Override
    public AdminAreaVo selectAreaAllById(int id) {
        AdminAreaVo adminAreaVo = areaDao.selectAllById(id);
        if (adminAreaVo!=null){
            AreaDto areaDto = areaDao.selectAllByCode(adminAreaVo.getAId());
            if (areaDto!=null){
                AreaDto areaDto1 = areaDao.selectAllByCode(areaDto.getPId());
                if (areaDto1!=null){
                    AreaDto areaDto2 = areaDao.selectAllByCode(areaDto1.getPId());
                    adminAreaVo.setCode1(areaDto2.getId());
                    adminAreaVo.setCodename1(areaDto2.getName());
                    adminAreaVo.setCode2(areaDto1.getId());
                    adminAreaVo.setCodename2(areaDto1.getName());
                    adminAreaVo.setCode3(areaDto.getId());
                    adminAreaVo.setCodename3(areaDto.getName());
                }
            }
        }
        return adminAreaVo;
//        AreaDao areaDao = this.areaDao.selectAllByCode();
//        return adminAreaVo;
    }
//        AreaDto areaDto = areaDao.selectAllById(aId);
//        List<StoreVo> storeVos = storeDao.selectStoreListByAid(aId);
//        ArrayList<StoreVo> storeVoArrayList = new ArrayList<>();
//        for (int i = 0; i < storeVos.size(); i++) {
//            StoreVo storeVo = storeDao.selectForStoreId(storeVos.get(i).getAId());
//            if (storeVo != null) {
//                List<Integer> integers = (List<Integer>) storeVo;
//                for (Integer pid : integers) {
//                    AreaNameVo areaNameVos1 = storeDao.selectAreaList(pid);
//                    if (areaNameVos1 != null) {
//                        AreaNameVo areaNameVo2 = storeDao.selectAreaList(areaNameVos1.getPId());
//                        if (areaNameVo2 != null) {
//                            AreaNameVo areaNameVo3 = storeDao.selectAreaList(areaNameVo2.getPId());
//                            storeVo.setA1(areaNameVos1);
//                            storeVo.setA2(areaNameVo2);
//                            storeVo.setA3(areaNameVo3);
//                        }
//                    }
//                }
//                storeVoArrayList.add(storeVo);
//            }
//            areaDto.setStoreVos(storeVoArrayList);
//        }
//        return areaDto;




//
//        AreaNameVo areaNameVo = storeDao.selectAreaList(storeVo.getAId());
//        if (areaNameVo!=null){
//            AreaNameVo areaNameVo1 = storeDao.selectAreaList(areaNameVo.getPId());
//            if (areaNameVo1!=null){
//                AreaNameVo areaNameVo2 = storeDao.selectAreaList(areaNameVo1.getPId());
//                storeVo.setA1(areaNameVo);
//                storeVo.setA2(areaNameVo1);
//                storeVo.setA3(areaNameVo2);
//            }
//        }
//
//        List<AreaAndStoreVo> areaAndStoreVos = areaDao.selectAreaAllById(sId);
//        return areaAndStoreVos;


    @Override
    public List<GradeDto> selectGrade() {
        List<GradeDto> gradeDtos = areaDao.selectGrade();
        return gradeDtos;
    }

    @Override
    public int addArea(AreaNameVo areaNameVo) {

        int i = areaDao.addArea(areaNameVo);
        return i;
    }

    @Override
    public int updateArea(UpdateAreaDto updateAreaDto) {
        int i = areaDao.updateArea(updateAreaDto);
        return i;
    }
}
